
package com.catsic.zcjc.specifiction;

import java.util.List;

import javax.persistence.criteria.Path;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import com.catsic.base.specification.BaseSpec;
import com.catsic.base.specification.QueryWraper;
import com.catsic.zcjc.condition.EquipCondition;
import com.catsic.zcjc.entity.Equip;

public class EquipSpec extends BaseSpec<Equip> {

	public EquipSpec(EquipCondition condition){
		super(condition);
	}
	

	@Override
	protected void addCondition(QueryWraper<Equip> queryWraper) {
		EquipCondition condition = (EquipCondition) getCondition();
		addLikeCondition(queryWraper, "name");
		this.addEqualCondition(queryWraper, "type");
		
		/**
		 * 多表联查,多对一,机构
		 */
		String stationId = condition.getStationId();
		if(StringUtils.isNotBlank(stationId)){
			Path<Equip> station = queryWraper.getRoot().get("station");
			addEqualCondition(queryWraper, station.get("id"),stationId);
		}
		
		List<String> stationIdList = condition.getStationIdList();
		if(!CollectionUtils.isEmpty(stationIdList)){
			Path<Equip> station = queryWraper.getRoot().get("station");
			addInCondition(queryWraper, station.get("id"),stationIdList);
		}
		
		String systemId = condition.getSystemId();
		if(StringUtils.isNotBlank(systemId)){
			Path<Equip> system = queryWraper.getRoot().get("system");
			addEqualCondition(queryWraper, system.get("id"),systemId);
		}
		
		List<String> systemIdList = condition.getSystemIdList();
		if(!CollectionUtils.isEmpty(systemIdList)){
			Path<Equip> system = queryWraper.getRoot().get("system");
			addInCondition(queryWraper, system.get("id"),systemIdList);
		}
	
		/**
		 * 自定义排序
		 */
		queryWraper.addOrder(queryWraper.getCb().asc(queryWraper.getRoot().get("code")));
	    
		
	}
}
